package com.heima.wemedia.feign;


import com.heima.model.admin.dtos.NewsAuthDto;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.dtos.SensitivePageDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import com.heima.wemedia.service.WmSensitiveService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;

/**
 * @author yht
 * @date 2022/1/13 14:19
 */
@RestController
@Slf4j
public class WemediaClient {
    @Autowired
    private WmNewsService wmNewsService;
    @Autowired
    private WmChannelService wmChannelService;
    /**
     * 查询自动审核的文章
     * @return
     */
    @PostMapping("/api/v1/wemedia/findautoauditlose")
    public PageResponseResult findAutoAuditLose(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.findAutoAuditLose(newsAuthDto);
    }

    /**
     * 根据id查询文章详情信息
     * @param id
     * @return
     */
    @GetMapping("/api/v1/wemedia/findnewbyid/{id}")
    public ResponseResult findNewById(@PathVariable("id") Integer id){
        return wmNewsService.findNewById(id);
    }

    /**
     * 文章审核驳回
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/wemedia/authfail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.authFail(newsAuthDto);
    }


    /**
     * 文章审核成功
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/wemedia/authpass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.authPass(newsAuthDto);
    };

    @Autowired
    WmSensitiveService sensitiveService;


    @PostMapping("/api/v1/sens/list")
    public ResponseResult findbylist(@RequestBody SensitivePageDto pageDto) {
        return sensitiveService.findlist(pageDto);
    }


    @PostMapping("/api/v1/sens/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return sensitiveService.del(id);
    }


    @PostMapping("/api/v1/sens/save")
    public ResponseResult create(@RequestBody WmSensitive wmSensitive) throws InvocationTargetException, IllegalAccessException {
        return sensitiveService.create(wmSensitive);
    }


    @PostMapping("/api/v1/sens/update")
    public ResponseResult update(@RequestBody SensitiveDto sensitiveDto) throws InvocationTargetException, IllegalAccessException {
        return sensitiveService.update(sensitiveDto);
    }

    /***
     * 查询频道列表
     * @return
     */
    @GetMapping("/api/v1/channel/list")
    public ResponseResult getChannels(){
        return wmChannelService.findAll();
    };
}
